// 暴力解法
fn rs_main1(nums: Vec<i32>, target: i32) -> Vec<i32> {
  let len1 =  nums.len();
  let len2 =  len1 - 1;
  for i in 0..len2 {
    for j in i+1..len1 {
      if nums[i] + nums[j] == target {
        return vec![i as i32, j as i32];
      }
    }
  }
  return vec![-1, -1];
}

// hash解法
fn rs_main2(nums: Vec<i32>, target: i32) -> Vec<i32> {
  use std::collections::HashMap;
  let len = nums.len();
  let mut map: HashMap<i32, i32> = HashMap::with_capacity(len);
  for i in 0..len {
      let num = nums[i];
      let value = map.get(&(target - num));
      if value.is_some() {
        return vec![*value.unwrap(), i as i32];
      }
      map.entry(num).or_insert(i as i32);
  }
  return vec![-1, -1];
}

fn main() {
  println!("{:?}", rs_main1(vec![2, 7, 11, 15], 9));
  println!("{:?}", rs_main1(vec![3, 2, 4], 6));
  println!("{:?}", rs_main1(vec![3, 3], 6));
  println!("{:?}", rs_main2(vec![2, 7, 11, 15], 9));
  println!("{:?}", rs_main2(vec![3, 2, 4], 6));
  println!("{:?}", rs_main2(vec![3, 3], 6));
}
